// 首页商品列表

//<!-- Swiper JS -->
window.onload=function(){
var swiper = new Swiper(".mySwiper", {
    loop: true,
    autoplay: true,
  });


$.ajax({
    type: "get",
    url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
    data: {
        uid:localStorage.getItem("id")
    },
    success: function (data) {
        console.log(data);
        let cartUl=document.querySelector('.cartUl');
        let str=""
        for (let id in data.data) {
            str += `
            <li class="fl">
                <a href="#" class="detail" data-id=${data.data[id].pid}>
                    <div class="goodlist">
                        <img src=${data.data[id].pimg} alt="">
                    </div>
                    <div class="fl">
                        <p>${data.data[id].pname}</p>
                        <p>${data.data[id].pdesc}</p>
                    </div>
                    <div class="fr">
                        <span class="xianjia">${data.data[id].pprice}</span>
                        <span class="yuanjia">${data.data[id].pprice}</span>
                    </div>
                </a>
            </li>
            `;
          }
          cartUl.innerHTML = str;
          let detail=document.querySelectorAll('.detail');
          for(let i=0;i<detail.length;i++){
              detail[i].onclick=function(){
                  let id=this.getAttribute("data-id");
                  console.log(id);
                //   localStorage .setItem("id",id)
                  location.href="详情页.html?id="+id
                  
              }
          }
    }
});}